<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link type="text/css" REL="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.js"></script>
    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script type="text/javascript" src="/webjars/axios/0.19.0/dist/axios.js"></script>
</head>
<body>

<div id="vuebox">
    <div class="container" style="margin-top: 50px;">
        <div class="row">
            <div class="col-md-6">
                <form class="form-inline" role="form" style="padding-left: 250px;">

                    <div class="form-group" style="padding-left: 20px;" >
                        <label>按区域查询:</label>
                        <select class="form-control" v-model="dis">
                            <option value="0">不限</option>
                            <option v-for="item in categoryList.data" :value="item.id">{{item.name}}</option>
                        </select>
                    </div>
                    <div class="form-group"  style="padding-left: 20px;">
                        <button type="button" class="btn btn-primary" @click="selectEntry(1)">查找</button>
                    </div>

                </form>
            </div>
            <div class="col-md-4 text-right">
                <a @click="showModal()" class="btn btn-primary">添加空气质量信息</a>
            </div>

            <br/>
            <br/>
            <table class="table table-striped">
                <thead>
                <tr>
                    <th>序号</th>
                    <th>区域</th>
                    <th>检测时间</th>
                    <th>PM10数据</th>
                    <th>PM2.5数据</th>
                    <th>监测站</th>
                    <th>最后的时间</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="item in seleAir.data.list">
                    <td>{{item.id}}</td>
                    <td>{{item.districtid}}</td>
                    <td>{{item.monitortime}}</td>
                    <td>{{item.pm}}</td>
                    <td>{{item.pms}}</td>
                    <td>{{item.monitoringstation}}</td>
                    <td>{{item.lastmodifytime}}</td>
<td>
    <button class="btn btn-success" @click="update(item.id)">修改</button>
    <button class="btn btn-danger"@click="dele(item.id)">删除</button>
</td>
                </tr>
                </tbody>
            </table>
            <br/>
            <ul class="pagination">
                <li v-show="seleAir.data.hasPreviousPage">
                    <a href="#" @click.prevent="selectEntry(seleAir.data.prePage)">&laquo;</a>
                </li>
                <li v-for="i in seleAir.data.navigatepageNums" :class="{active:seleAir.data.pageNum==i}">
                    <a href="#" @click.prevent="selectEntry(i)">{{i}}</a>
                </li>
                <li v-show="seleAir.data.hasNextPage">
                    <a href="#" @click.prevent="selectEntry(seleAir.data.nextPage)">&raquo;</a>
                </li>

            </ul>
        </div>
    </div>


    <!--模态框-->
    <div class="modal" id="mymodal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" type="button" @click="hideModal()">&times;</button>
                    <div class="modal-title">
                       添加空气
                    </div>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">

                        <div class="form-group">
                                <label for="districtid" class="col-sm-2 control-label">检测分类</label>
                            <div class="col-sm-10">
                                <select id="districtid" class="form-control" v-model="add.districtid">
                                    <option value="0">全部</option>
                                    <option v-for="item in categoryList.data" :value="item.id">{{item.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="monitortime" class="col-sm-2 control-label">时间</label>
                            <div class="col-sm-10">
                                <input v-model="add.monitortime" id="monitortime" type="text" class="form-control" placeholder="请输入图书名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pm" class="col-sm-2 control-label">pm值</label>
                            <div class="col-sm-10">
                                <input v-model="add.pm" id="pm" type="text" class="form-control" placeholder="请输入图书摘要"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pms" class="col-sm-2 control-label">pms</label>
                            <div class="col-sm-10">
                                <input v-model="add.pms" id="pms" type="text" class="form-control" placeholder="请输入上传人">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="monitoringstation" class="col-sm-2 control-label">检测站</label>
                            <div class="col-sm-10">
                                <input v-model="add.monitoringstation" id="monitoringstation" type="text" class="form-control" placeholder="请输入上传时间">
                            </div>
                        </div>

                    </form>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" @click="hideModal()">关闭</button>
                    <button class="btn btn-primary" @click="saveEntry()">保存</button>
                </div>
            </div>
        </div>
    </div>

</div>

</body>
</html>

<script type="text/javascript">
    var vm=new Vue({
        el:"#vuebox",
        data:{
            categoryList:{},
            seledis:{},
            seleAir:{},
            dis:0,
pageNum:'',
deleResult:{},
            districtid:0,
            add:{id:'',districtid:'0',monitortime:'',pm:'',pms:'',monitoringstation:''},

        },
        methods:{
            selectEntry:function (cid) {
                axios.get("/sele",{params:{pageNum:cid,districtId:this.dis}}).then(res=>{this.seleAir=res.data})
        },
dele:function (id) {
    axios.get("/deleByid",{params: {id:id}}).then(res=>{
this.deleResult=res.data;
if (this.deleResult.result=='SUCCESS'){
this.selectEntry(this.pageNum);
alert("删除成功!!!");
}
else {
alert(this.deleResult.message);
    alert("删除失败!!!");
}
    })
},
            showModal:function () {
                $("#mymodal").modal("show");
            },
            hideModal:function () {
                $("#mymodal").modal("hide");
                this.clearRorm();
            },
            clearRorm:function () {
                $('#districtid').val(0);
                $('monitortime').val('');
                $('pm').val('');
                $('pms').val('');
                $('monitoringstation').val('');
            },
            saveEntry:function () {
                axios.post("/saveEntry",this.add).then(res=>{
                    this.add=res.data;
                    if (this.add.result=='SUCCESS'){
                        this.selectEntry(this.pageNum);
                        this.hideModal();
                    }
                    else {
                        alert(this.add.message);

                    }
                })
            },
            update:function (id) {
                axios.get("/getEntryById",{params:{id:id}}).then(res=>{
                    this.add=res.data.data;
                    this.showModal();
                })
            }
            


        },
        mounted(){
            axios.get("/getbyid").then(res=>{this.categoryList=res.data})
            this.selectEntry(1)
        }
    })
</script>
